var t = require("../../../utils/themeSkin/skinBehavior"), a = getApp();

Page({
    behaviors: [ t ],
    data: {
        Height: 0,
        LastHeight: 0,
        choose_index: 1,
        SearchValue: "",
        current_page: 1,
        last_page: 1,
        list: [],
        CarouseList: [],
        language: "",
        order_type: 0,
        search_type: 0,
        sort: {
            up: 0,
            down: 0
        },
        category_list: [],
        category_10: [],
        category_index: 0,
        cate_id: ""
    },
    getCategoryGoods: function(t) {
        var a = t.currentTarget.dataset.id, e = t.currentTarget.dataset.index;
        this.setData({
            category_index: e,
            cate_id: a
        }), this.getData({
            page: 1,
            order_type: this.data.order_type,
            search_type: this.data.search_type,
            cate_id: a
        });
    },
    imgHeight: function(t) {
        var a = wx.getSystemInfoSync().windowWidth;
        if (t && t.detail) {
            var e = a * t.detail.height / t.detail.width;
            parseInt(e) > this.data.LastHeight && (this.setData({
                Height: e
            }), this.data.LastHeight = parseInt(e));
        }
    },
    onLoad: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        }), this.getCarouse(), this.getCategory(), this.buttonGroup(), this.getData({
            page: 1
        }), this.imgHeight();
    },
    getCategory: function() {
        var t = this;
        a._getNetWork({
            url: a.getNetAddresss("plugin.tiktok-cps.api.goods.good-recommend-cate"),
            success: function(e) {
                if (0 == e.data.result) return a.tips(result.data.msg);
                t.setData({
                    category_list: e.data.data || []
                });
            }
        });
    },
    buttonGroup: function() {
        var t = this;
        a._getNetWork({
            url: a.getNetAddresss("plugin.tiktok-cps.api.goods.button-group"),
            success: function(e) {
                if (0 == e.data.result) return a.tips(result.data.msg);
                if (e.data.data && e.data.data.length >= 1) {
                    var s = t.chunk(e.data.data, 10);
                    t.setData({
                        category_10: s
                    });
                }
            }
        });
    },
    chunk: function(t, a) {
        for (var e = [], s = 0, r = t.length; s < r; s += a) e.push(t.slice(s, s + a));
        return e;
    },
    link_detail: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageF/cps/detail/detail?goods_id=" + a
        });
    },
    getCarouse: function() {
        var t = this;
        a._getNetWork({
            url: a.getNetAddresss("plugin.tiktok-cps.api.rotation.rotation-list"),
            success: function(e) {
                if (0 == e.data.result) return a.tips(e.data.msg);
                t.setData({
                    CarouseList: e.data.data || []
                });
            }
        });
    },
    choose: function(t) {
        var a = t.currentTarget.dataset.index;
        this.setData({
            choose_index: a
        }), 1 !== a ? 0 == this.data.sort.up && 0 == this.data.sort.down ? this.setData({
            "sort.up": 1,
            "sort.down": 0
        }) : 1 == this.data.sort.up && 0 == this.data.sort.down ? this.setData({
            "sort.up": 0,
            "sort.down": 1
        }) : 0 == this.data.sort.up && 1 == this.data.sort.down && this.setData({
            "sort.up": 1,
            "sort.down": 0
        }) : 1 == a && this.setData({
            "sort.up": 0,
            "sort.down": 0
        }), 1 == this.data.sort.down ? this.setData({
            order_type: 1
        }) : this.setData({
            order_type: 0
        });
        var e = a - 1;
        this.setData({
            search_type: e
        }), this.getData({
            page: 1,
            order_type: this.data.order_type,
            search_type: e,
            cate_id: this.data.cate_id
        });
    },
    link: function(t) {
        var a = t.currentTarget.dataset.url;
        wx.navigateTo({
            url: a
        });
    },
    getData: function(t) {
        var e = this;
        a._getNetWork({
            url: a.getNetAddresss("plugin.tiktok-cps.api.goods.good-list"),
            data: t,
            success: function(s) {
                var r = s.data;
                if (0 == r.result) return a.tips(r.msg);
                if (1 == t.page) e.setData({
                    list: r.data.products
                }); else if (t.page > 1) {
                    var i = e.data.list.concat(r.data.products);
                    e.setData({
                        list: i
                    });
                }
                e.setData({
                    current_page: r.data.current_page,
                    last_page: r.data.last_page
                });
            }
        });
    },
    getMoreData: function() {
        if (!(this.data.current_page >= this.data.last_page)) {
            var t = Number(this.data.current_page) + 1;
            this.getData({
                page: t,
                order_type: this.data.order_type,
                search_type: this.data.search_type,
                cate_id: this.data.cate_id
            });
        }
    },
    link_search: function() {
        wx.navigateTo({
            url: "/packageF/cps/search/search"
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.getMoreData();
    },
    onShareAppMessage: function() {}
});